package threadLock.threadBasics.interrupt;

/**
 * 线程睡眠之后 在规定时间自醒
 * 也可以通过打断让线程提前醒
 */
public class SleepInterrupt {
    public static void main(String[] args) throws InterruptedException {
        Thread threadOne = new Thread(() -> {
            try {
                System.out.println("threadOne begin sleep for 20 seconds");
                Thread.sleep(200000);
                System.out.println("threadOne awaking");
            } catch (InterruptedException e) {
                System.out.println("threadOne is interrupt while sleeping");
                return;
            }
            System.out.println("threadOne-leaving normally");
        });
        threadOne.start();
        Thread.sleep(1000);
        threadOne.interrupt();
        threadOne.join();
        System.out.println("main thread is over");
    }
}
